package com.gxl.butt.DAO.impl;

import com.gxl.butt.DAO.IbtipDAO;
import com.gxl.butt.DAO.IbttokenDAO;
import com.gxl.butt.domain.BT_Ip;
import com.gxl.butt.domain.BT_Token;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * Created by GUOXIAOLIN on 2018/7/13.
 */
@Repository
public class BtipDAOImpl extends HibernateBaseDao<BT_Ip> implements IbtipDAO {

    @Override
    public Long saveBtIp(BT_Ip bt_ip) {

        return (Long) this.save(bt_ip);

    }

    @Override
    public boolean delIpById(Long id) {
        this.delete(id);
        return true;

    }

    @Override
    public List<BT_Ip> getIpListByUserId(Long userid) {

        String hql = "select id,ip from " + BT_Ip.class.getName() + " do where do.userid = " + userid;
        List<BT_Ip>  bt_ips = this.getListByHql(hql);
        if (bt_ips != null && bt_ips.size() > 0){
            return bt_ips;
        }
        return null;
    }

    @Override
    public List<BT_Ip> getListByIpAndUserId(String ip, Long userid) {

        String hql = "select id,ip from " + BT_Ip.class.getName() + " do where do.userid = " + userid + " and  do.ip = '" + ip + "'";
        List<BT_Ip>  bt_ips = this.getListByHql(hql);
        if (bt_ips != null && bt_ips.size() > 0){
            return bt_ips;
        }
        return null;
    }

    @Override
    public List<BT_Ip> getListByIpAndOpenid(String ip, String openid) {

        String hql = "select id,ip from " + BT_Ip.class.getName() + " do where do.openid = '" + openid + "' and  do.ip = '" + ip + "'";
        List<BT_Ip>  bt_ips = this.getListByHql(hql);
        if (bt_ips != null && bt_ips.size() > 0){
            return bt_ips;
        }
        return null;
    }

    @Override
    public List<BT_Ip> getipsByOpenid(String openid) {
        String hql = "select id,ip from " + BT_Ip.class.getName() + " do where do.openid = '" + openid + "' order by id desc";
        List<BT_Ip>  bt_ips = this.getListByHql(hql);
        if (bt_ips != null && bt_ips.size() > 0){
            return bt_ips;
        }
        return null;
    }
}
